(function() {
  'use strict';
  angular.module('controllers.dataManager.dataQualityMonitor')
    .controller('dataQualityReportCtrl', dataQualityReportCtrl);

  function dataQualityReportCtrl($scope, $filter, dataQualityReportFactory, dataQualityMonitorService, CoreLoading) {
    var time = new Date();
    var date = new Date(time.getFullYear(), time.getMonth(), time.getDate() - 1);
    $scope.params = {
      date: date
    };
    $scope.flag = {
      arrow: false,
      state: true, //显示查询面板
      show: 'chart'
    }
    var myEcharts = echarts.init(document.getElementById('reportChart'));
    var param = {}; // 临时数据集合
    /**
     * 查询方法
     */
    $scope.search = function() {
      if (!$scope.flag.state) {
        $scope.flag.state = true;
        return;
      }
      param = angular.copy($scope.params);
      param.date = $filter('date')(param.date, 'yyyy-MM-dd');
      $scope.title = $filter('date')(param.date, 'yyyy年MM月dd日') + '各业务线数据质量报告';
      CoreLoading.setState(true);
      dataQualityReportFactory.query(param, function(res) {
        if (res.state === '10000' && res.data.data.length >= 1) {
          myEcharts.clear();
          $scope.flag.state = false;
          $scope.flag.arrow = false;
          $scope.flag.show = 'chart';
          $scope.dataList = res.data.data;
          $scope.stateName = res.data.stateName;
          var option = dataQualityReportFactory.initChart($scope.dataList, $scope.title);
          myEcharts.setOption(option);
        } else {
          dataQualityMonitorService.queryError($scope.flag, '查询无数据');
        }
        CoreLoading.setState(false);
      });
    };
    $scope.search();
  }

  dataQualityReportCtrl.$inject = ['$scope', '$filter', 'dataQualityReportFactory', 'dataQualityMonitorService', 'CoreLoading'];
})();